package com.leetcode.www;

/**
 * Creared with IntelliJ IDEA.
 * Description:给定一个整数 num，将其转化为 7 进制，并以字符串形式输出。
 * User:yxd
 * Date:2022-03-16
 * Time:11:40
 */
public class Everyday504 {
    public String convertToBase7(int num) {
        if(num == 0)return "0";
        StringBuilder sb = new StringBuilder();
        int x = num;
        num = Math.abs(num);
        while(num != 0){
            int a = num % 7;
            num = num / 7;
            sb.append(String.valueOf(a));//转换为字符串
        }
        if(x < 0){
            sb.append("-");
        }
        return sb.reverse().toString();//反转后输出
    }
}
